

/*

console.log("shein block");
var type = "sheinblock";

if(location.href.includes("s1.shein.com")){
    type = "sheinblock_yn";
}

chrome.runtime.sendMessage({ data: {type }, close: false })
*/


if(location.href.includes("s1.shein.com")){
    if(getQueryString("captcha_type")==='905'){
       /* let type = "yuenanstock";
        console.log("yuenanstock bolck")
        chrome.runtime.sendMessage({ data: {type }, close: false })

        */
        //window.close();
    }
}




function getQueryString(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    let r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return r[2];
    };
    return 0;
}

var checkItervalId = setInterval(()=>{
    checkPopSuccess();
},2000)



var no_pop_time = 0 ;
var all_check_times = 0;
function checkPopSuccess(){
    all_check_times++;
    console.log("all_check_times",all_check_times);

    const high_closeBox = document.querySelector('.captcha_click_close_box');
    if (high_closeBox) {
        console.log("high_closeBox",high_closeBox);
        block();
    }

    const closeBox = document.querySelector('.captcha_canvas_close_box');
    //已经确定有滑动窗口
    if (!closeBox) {
        console.log("checkPopSuccess","no closeBox");
    }

    //已经计算好了滑动窗口需要移动多少
    if(closeBox && sm_left_px_move > 0){
        console.log("sm_left_px_move",sm_left_px_move);
        if(start_move===false){
            chrome.runtime.sendMessage({ data: {type:"focusTab"}, close: false });
            // console.log("start_move",start_move);
            start_move = true;
            setTimeout(() => {
                simulateSlider(sm_left_px_move).then(() => {
                    console.log("滑块滑动完成！");
                    setTimeout(() => {
                        start_move = false;
                        console.log("set_start_move",start_move);
                    },1500);
                });
            },500);
        }
    }

    const goods_btn = document.querySelector('.goods-btn__add');
    console.log("set goods_btn",goods_btn);
    if(goods_btn){
        header_can_user = true;
        console.log("set header_can_user",header_can_user);
    }

    if(!closeBox && !goods_btn){
        no_pop_time++;
        console.log("no_pop_time",no_pop_time);
        if(no_pop_time > 10){
            //page_reload();
        }
    }
    if(all_check_times > 3){
        //location.reload();
    }
}

var start_move = false;

var reRryTime = 0;



var sm_left_px_move = 0;
var api1_fail_number = 0;
var api2_fail_number = 0;
var api3_fail_number = 0;
var api4_fail_number = 0;
var success_time = 0;

var header_quickView = "";
var header_header_static_v2 = "";
var header_header_realtime = "";
var useLocalHeader_realtime = false;
var useLocalHeader_quickview = false;
var last_fail_api_index = 0 ;
var run_index = 0;
var sm_eror = false;
var run_number = 0;
var check_pop_success = true;
var header_can_user = false;
chrome.runtime.onMessage.addListener(async (msg, sender) => {

    if(msg.type==='sm_pic'){
        console.log(msg.pic)
        findLargestTransparentAreaByUrl(msg.pic).then(leftMostX => {
            if(leftMostX > 0){
                sm_left_px_move = leftMostX;
            }
            console.log('Left Most X:', leftMostX);
        })
            .catch(error => {
                console.error('Error:', error);
                page_reload();
            });
    }

})

